<template>
  <el-descriptions :column="3" border size="medium">
    <template slot="title">
      <el-button type="primary" @click="handleBack">返回</el-button>
      <el-button type="primary" v-if="type !== 2" @click="handleSubmit">提交</el-button>
    </template>
    <template slot="extra">
      <slot name="extra"></slot>
    </template>
    <!-- <el-descriptions-item label="试卷名称">
      <el-input v-model="formData.name"></el-input>
    </el-descriptions-item>
    <el-descriptions-item label="试卷类型">
      <el-select v-model="formData.paperType">
        <el-option
          v-for="(value, key) in getObj('paperTypeEnum')"
          :key="key"
          :label="value"
          :value="+key"
        >
        </el-option>
      </el-select>
    </el-descriptions-item> -->
    <el-descriptions-item v-for="item in cols" :key="item.key" :label="item.label">
      <template v-if="type === 2">
        <template v-if="item.formatter">
          <span>
            {{ item.formatter(formData[item.key]) }}
          </span>
        </template>
        <span v-else>{{ formData[item.key] }}</span>
      </template>
      <template v-if="type < 2">
        <el-select v-model="formData[item.key]" v-if="item.type === 'select'">
          <el-option
            v-for="(value, key) in getObj([item.selectDataEnum])"
            :key="key"
            :label="value"
            :value="+key"
          >
          </el-option>
        </el-select>
        <el-date-picker
          v-else-if="item.type === 'datetime'"
          v-model="formData[item.key]"
          type="datetime"
          value-format="timestamp"
        ></el-date-picker>
        <el-input v-model="formData[item.key]" v-else></el-input>
      </template>
    </el-descriptions-item>
  </el-descriptions>
</template>

<script>
  import { mapGetters } from 'vuex'
  export default {
    name: 'Descriptions',
    props: {
      cols: Array,
      formData: Object,
      type: Number | String
    },
    computed: {
      ...mapGetters(['subjectEnum', 'paperTypeEnum', 'questionTypeEnum', 'levelEnum'])
    },
    methods: {
      handleBack() {
        this.$router.go(-1)
      },
      handleSubmit() {
        this.$emit('submit', this.formData)
      },
      getObj(key) {
        return this[key]
      }
    }
  }
</script>

<style></style>
